package com.example.pingtools.adpater

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.animation.AnimationUtils
import android.widget.*
import androidx.recyclerview.widget.RecyclerView
import com.example.pingtools.R
import com.example.pingtools.base.CallBack
import com.example.pingtools.bean.FloderBean

class MenuAd(private val textList: List<FloderBean>) :
    RecyclerView.Adapter<MenuAd.MyViewHolder>() {
    private var itemClickListener: IKotlinItemClickListener? = null

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): MyViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.item_recycler, parent, false)
        return MyViewHolder(view)
    }

    override fun getItemCount(): Int = textList.size ?: 0

    override fun onBindViewHolder(holder: MenuAd.MyViewHolder, position: Int) {
        holder.tvcontent.animation =
            AnimationUtils.loadAnimation(holder.itemView.context, R.anim.example_anims)
        var textpos = textList[position]
       // Log.d("xxxxxxxxxxx",textList[position])
       // holder.title.text = textpos
        holder.title.text=textpos.name
        holder.itemView.setOnClickListener {
            itemClickListener!!.onItemClickListener(position)
        }
        holder.tvdel.setOnClickListener{
            itemClickListener!!.onItemClickListenerdel(position)
        }
    }

    class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var title: TextView = itemView.findViewById(R.id.tv_name)
        var tvdel:TextView=itemView.findViewById(R.id.tv_del)
        var tvcontent: RelativeLayout=itemView.findViewById(R.id.content)

    }

    // 提供set方法
    fun setOnKotlinItemClickListener(itemClickListener: IKotlinItemClickListener) {
        this.itemClickListener = itemClickListener
    }

    //自定义接口
    interface IKotlinItemClickListener {
        fun onItemClickListener(position: Int)
        fun onItemClickListenerdel(position: Int)
    }
}